<?php
set_include_path(get_include_path() . ":/home/http/kodform4/lib");
require_once 'PHPUnit/Framework.php';

require_once 'Kodvalid.php';
require_once 'Kodform/Filter/Trim.php';
require_once 'Kodform/Validator/Required.php';
require_once 'Kodform/Validator/Regex.php';

class KodvalidTests extends PHPUnit_Framework_TestCase{
	protected $validators;
	protected function setUP(){
		$this->validators = new Kodvalid(array("test1", "test2", "test3"));
		$this->validators->addFilter("test1", new Kodform_Filter_Trim())
						 ->addValidator("test1", new Kodform_Validator_Regex("'testrim'", "Nesto smrdi u regexu"))
						 ->addValidator("test3", new Kodform_Validator_Regex("'erdrd'", "Ovo nije email"))
						 ->addValidator("test3", new Kodform_Validator_Regex("'e'", "Ovo nije email 2 put"))
						 ->addValidator("test2", new Kodform_Validator_Required("test2 mora sadrzati vrijednost"));
		$this->validators->setValues(array("test1" => "   testrim  ", "test2" => null, "test3" => "erf@gmail.com"));
	}
	public function testReturnValue(){
		$this->assertFalse($this->validators->isAllValid());
	}
	public function testCountErrors(){
		$errors = $this->validators->getAllErrors();
		$this->assertEquals(count($errors), 2);
	}
	public function testCountOneErrors(){
		$errors = $this->validators->getErrors("test3");
		$this->assertEquals(count($errors), 2);
	}
}